package com.gnerv.battle.boot.project.service.impl;

import com.gnerv.battle.boot.project.entity.MonitorProjectMiddleware;
import com.gnerv.battle.boot.project.dao.MonitorProjectMiddlewareDao;
import com.gnerv.battle.boot.project.service.MonitorProjectMiddlewareService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 监控项目中间件表(MonitorProjectMiddleware)表服务实现类
 *
 * @author makejava
 * @since 2024-05-26 11:22:02
 */
@Service("monitorProjectMiddlewareService")
public class MonitorProjectMiddlewareServiceImpl implements MonitorProjectMiddlewareService {
    @Resource
    private MonitorProjectMiddlewareDao monitorProjectMiddlewareDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public MonitorProjectMiddleware queryById(Long id) {
        return this.monitorProjectMiddlewareDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param monitorProjectMiddleware 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<MonitorProjectMiddleware> queryByPage(MonitorProjectMiddleware monitorProjectMiddleware, PageRequest pageRequest) {
        long total = this.monitorProjectMiddlewareDao.count(monitorProjectMiddleware);
        return new PageImpl<>(this.monitorProjectMiddlewareDao.queryAllByLimit(monitorProjectMiddleware, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param monitorProjectMiddleware 实例对象
     * @return 实例对象
     */
    @Override
    public MonitorProjectMiddleware insert(MonitorProjectMiddleware monitorProjectMiddleware) {
        this.monitorProjectMiddlewareDao.insert(monitorProjectMiddleware);
        return monitorProjectMiddleware;
    }

    /**
     * 修改数据
     *
     * @param monitorProjectMiddleware 实例对象
     * @return 实例对象
     */
    @Override
    public MonitorProjectMiddleware update(MonitorProjectMiddleware monitorProjectMiddleware) {
        this.monitorProjectMiddlewareDao.update(monitorProjectMiddleware);
        return this.queryById(monitorProjectMiddleware.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.monitorProjectMiddlewareDao.deleteById(id) > 0;
    }
}
